{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import rabbitpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "with rabbitpy.Connection() as connection:\n",
    "    with connection.channel() as channel:           \n",
    "        tx = rabbitpy.Tx(channel)\n",
    "        tx.select()\n",
    "        message = rabbitpy.Message(channel,\n",
    "                                   'This is an important message',    \n",
    "                                   {'content_type': 'text/plain',\n",
    "                                    'delivery_mode': 2,               \n",
    "                                    'message_type': 'important'}) \n",
    "        message.publish('chapter4-example', 'important.message')\n",
    "        try:\n",
    "            if tx.commit():     \n",
    "                print('Transaction committed')             \n",
    "        except rabbitpy.exceptions.NoActiveTransactionError:\n",
    "            print('Tried to commit without active transaction')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
